﻿<Window xmlns:controls="clr-namespace:Brjnk.GpxExplorer.UI.Controls"  xmlns:my="clr-namespace:Brjnk.GpxExplorer.UI"  x:Class="Brjnk.GpxExplorer.UI.SearchListWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:Brjnk.GpxExplorer.Localization"
        xmlns:common="clr-namespace:Brjnk.Common;assembly=Common"
        xmlns:workspace="clr-namespace:Brjnk.GpxExplorer.Workspace"
        xmlns:searching="clr-namespace:Brjnk.GpxExplorer.Workspace.Searching"
        WindowStartupLocation="CenterOwner"
        Title="{l:Loc titleSearchList}" SizeToContent="WidthAndHeight"
        MinWidth="400" ResizeMode="NoResize">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="330" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="200"></RowDefinition>
            <RowDefinition Height="200"></RowDefinition>
        </Grid.RowDefinitions>

        <ListView Name="list" ItemsSource="{Binding SearchedItems}">
            <ListView.ItemTemplateSelector>
                <common:GenericTemplateSelector>
                    <common:TemplateDefinition ObjectType="{x:Type searching:Pushpin}">
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="32" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Image Source="/Resources/Icons/PushpinSymbol.png" />
                                <TextBlock Text="{l:Loc searchListPushpin}" Grid.Column="1" />
                            </Grid>
                        </DataTemplate>
                    </common:TemplateDefinition>
                    <common:TemplateDefinition>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="32" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Ellipse Fill="{Binding Color1, Converter={StaticResource ColorToBrushConverter}}" Stroke="{Binding Color2, Converter={StaticResource ColorToBrushConverter}}" StrokeThickness="3" />
                                <TextBlock Text="{Binding StringRepresentation}" Grid.Column="1" />
                            </Grid>
                        </DataTemplate>
                    </common:TemplateDefinition>
                </common:GenericTemplateSelector>
            </ListView.ItemTemplateSelector>
        </ListView>

        <StackPanel Grid.Column="1">
            <Button Content="{l:Loc searchListRemove}" Command="{Binding RemoveItemCommand}" CommandParameter="{Binding ElementName=list, Path=SelectedItem}">
                <Button.Style>
                    <Style TargetType="Button" BasedOn="{StaticResource ResourceKey={x:Type Button}}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=list, Path=SelectedItems.Count}" Value="0">
                                <Setter Property="IsEnabled" Value="false" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
            <Button Content="{l:Loc searchListAddPosition}" Command="{Binding SearchPositionCommand}" />
            <Button Content="{l:Loc searchListAddPlace}" Command="{Binding SearchPlaceCommand}" />
            <Button Content="{l:Loc searchListAddTime}" Command="{Binding SearchDateTimeCommand}" />
            <Button Content="{l:Loc searchListShowDebugInfo}" Command="{Binding ShowDebugInfoCommand}" />
        </StackPanel>

        <ContentControl Grid.Row="1" Grid.ColumnSpan="2" Content="{Binding ElementName=list, Path=SelectedItem}">
            <ContentControl.ContentTemplateSelector>
                <common:GenericTemplateSelector>
                    <common:TemplateDefinition ObjectType="{x:Type searching:SearchDateTimeRequest}">
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{l:Loc searchListDateTime}" />
                                <TextBox Style="{StaticResource HeaderTextBoxStyle}" Name="timeTxb" Text="{Binding DateTime}" Grid.Row="1" />
                                <CheckBox Content="{l:Loc searchListSearchInGaps}" IsChecked="{Binding SearchInGaps}" />
                                <controls:ColorPicker Color="{Binding Color1}" />
                            </StackPanel>
                        </DataTemplate>
                    </common:TemplateDefinition>
                    <common:TemplateDefinition ObjectType="{x:Type searching:Pushpin}">
                        <DataTemplate>
                            <StackPanel>

                                <TextBlock Text="{l:Loc searchListPushpin}" />
                                <TextBlock Text="{Binding StringRepresentation}" FontWeight="Bold" />
                                <TextBox Name="coordinatesTxb" IsEnabled="False"  Style="{StaticResource HeaderTextBoxStyle}" Text="{Binding Position}" />
                                <my:SearchPositionArgsEditor Limit="{Binding MaxDistance, Mode=TwoWay}" SearchAgainLimit="{Binding ShowAgainDistance, Mode=TwoWay}" SearchInGaps="{Binding SearchInGaps, Mode=TwoWay}" />
                            </StackPanel>
                        </DataTemplate>
                    </common:TemplateDefinition>
                    <common:TemplateDefinition ObjectType="{x:Type searching:SearchPositionRequest}">
                        <DataTemplate>
                            <StackPanel>
                                <Grid>
                                    <TextBlock Text="{l:Loc searchListPosition}" />
                                    <my:GoToCoordinatesPanel ButtonAddPushpin="False"  HorizontalAlignment="Right" GpsCoordinates="{Binding Position}" />
                                </Grid>
                                <TextBox Name="coordinatesTxb"  Style="{StaticResource HeaderTextBoxStyle}" Text="{Binding Position}" />
                                <my:SearchPositionArgsEditor Limit="{Binding MaxDistance, Mode=TwoWay}" SearchAgainLimit="{Binding ShowAgainDistance, Mode=TwoWay}" SearchInGaps="{Binding SearchInGaps, Mode=TwoWay}" />
                                <controls:ColorPicker Color="{Binding Color1}" />
                            </StackPanel>
                        </DataTemplate>
                    </common:TemplateDefinition>
                </common:GenericTemplateSelector>
            </ContentControl.ContentTemplateSelector>
        </ContentControl>
    </Grid>
</Window>